package cn.akwangl.concurrency.web.model.order.controller;

import cn.akwangl.concurrency.web.common.Result;
import cn.akwangl.concurrency.web.model.order.pojo.OrderVo;
import cn.akwangl.concurrency.web.model.order.pojo.SubmitOrderDto;
import cn.akwangl.concurrency.web.model.order.service.CreateOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单表; 前端控制器
 * </p>
 *
 * @author 阿坤同学
 * @since 2022-11-22 14:29:53
 */
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    @Qualifier("ordersVersion")
    private CreateOrdersService ordersVersionService;

    @Autowired
    @Qualifier("zkOrdersService")
    private CreateOrdersService zkOrdersService;

    @PostMapping("/create")
    public Result create(@RequestBody SubmitOrderDto submitOrderDto) {
        // 1. 订单参数非空校验
        // 2. 创建订单
        OrderVo orderVo = ordersVersionService.createOrder(submitOrderDto);
        // 3. 更新cookie 购物车数据
        // 4. 向支付中心发放支付请求
        return Result.success(orderVo.getOrderId());
    }

    @PostMapping("/zkCreate")
    public Result zkCreate(@RequestBody SubmitOrderDto submitOrderDto) {
        // 1. 订单参数非空校验
        // 2. 创建订单
        OrderVo orderVo = zkOrdersService.createOrder(submitOrderDto);
        // 3. 更新cookie 购物车数据
        // 4. 向支付中心发放支付请求
        return Result.success(orderVo.getOrderId());
    }
}
